<template>
	<view class="container">
		<form @submit.prevent="submit">
			<view class="top-content">
				<label for="content">房屋编号:</label>
				<input type="text" :value="repairInfo.housesId" disabled />
			</view>
			<label for="content">报修内容:</label>
			<textarea id="content" v-model="repairInfo.content" placeholder="请输入报修内容" rows="5"></textarea>

			<label for="image-upload" class="upload-label">上传图片:</label>
			<UpLoadComponent ref="upload" />
			<!-- <input type="text" v-model="repairInfo.phone" placeholder="手机/邮箱/QQ(选填)"> -->

			<button @tap="submit" type="submit">提交</button>

		</form>
	</view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { insertRepair } from '../../services/repair';
import UpLoadComponent from '@/components/UpLoadComponent.vue';
import { onLoad } from '@dcloudio/uni-app';
const upload = ref(null);
const index = ref(-1);
const repairInfo = ref({
	content: '',
	image: [] as string[],
	repairStatus: 0,
	housesId: 0
});

onLoad((option) => {

	repairInfo.value.housesId = option.houseId

});

const submit = async () => {
	repairInfo.value.image = upload.value.image
	//判断表单
	if (repairInfo.value.content === '' || repairInfo.value.image.length === 0||repairInfo.value.houseId==0) {
		uni.showToast({
			title: '请填写完整信息',
			icon: 'none'
		});
		return;
	}
	await insertRepair(repairInfo.value);
};
</script>

<style scoped lang="scss">
.container {
	padding: 20px;
	background-color: #f0f0f0;
	border-radius: 8px;
	max-width: 600px;
	margin: 0 auto;
}
.top-content
{
	display: flex;
	justify-content: space-between;
	input{
		border: none;
	}
}
.picker-wrap {
	margin-bottom: 15px;
}

.uni-input {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 40px;
	border: 1px solid #ccc;
	border-radius: 4px;
	padding: 0 15px;
	cursor: pointer;
}

.uni-input.default-text {
	color: rgb(128, 128, 128);
}

.uni-input.selected-text {
	color: #000000;
}

textarea {
	width: 100%;
	min-height: 150px;
	padding: 10px;
	font-size: 14px;
	border: 1px solid #ccc;
	border-radius: 4px;
	resize: vertical;
}

input {
	width: 100%;
	height: 40px;
	margin-bottom: 15px;
	font-size: 14px;
	text-indent: 1em;
	
	border-radius: 4px;
	box-sizing: border-box;
	// border: 1px solid #ccc;
}




.input-file {
	border: 0;
}

.upload-label {
	cursor: pointer;
	margin-bottom: 5px;
	display: block;
	font-size: 16px;
	font-weight: bold;
}

button {
	background-color: #4CAF50;
	color: white;
	border: none;
	border-radius: 4px;
	font-size: 16px;
	cursor: pointer;
}

button:hover {
	background-color: #45a049;
}

button[type="submit"] {
	width: 100%;
}
</style>